package org.gitos.cloud.domain.redis;

import org.gitos.cloud.domain.device.Device;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * Created by shizhengchu on 16/3/17.
 */
public class DeviceRedisTemplate extends RedisTemplate<String, Device> {
    public DeviceRedisTemplate() {
        RedisSerializer<String> stringSerializer = new StringRedisSerializer();
        RedisSerializer jacksonSerializer = new GenericJackson2JsonRedisSerializer();
        setKeySerializer(stringSerializer);
        setValueSerializer(jacksonSerializer);
        setHashKeySerializer(stringSerializer);
        setHashValueSerializer(jacksonSerializer);
    }

    public DeviceRedisTemplate(RedisConnectionFactory connectionFactory) {
        this();
        setConnectionFactory(connectionFactory);
        afterPropertiesSet();
    }
}
